package me.keiwu.user.controller.rpc;

import me.keiwu.user.domain.Medal;
import me.keiwu.user.domain.MedalPresent;
import me.keiwu.user.service.MedalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by kei on 30/01/2018.
 */
@RestController
@RequestMapping("/rpc/medal")
public class MedalRpcController {

    @Autowired
    private MedalService medalService;

    @RequestMapping("/save")
    public Medal save(@RequestParam(required = false) Integer medalId,
                      String name, String url, Integer cost) {
        return medalService.saveMedal(medalId, name, url, cost);
    }


    @RequestMapping("/list")
    public Page<Medal> list(@RequestParam(defaultValue = "0") Integer page,
                            @RequestParam(defaultValue = "10") Integer size) {
        return medalService.findAllMedals(page, size);
    }


    @RequestMapping("shelve")
    public Medal shelve(Integer medalId, boolean shelve) {
        return medalService.shelve(medalId, shelve);
    }

    @RequestMapping("present/send")
    public MedalPresent sendMedalPresent(Integer presentId) {
        return medalService.sendMedalPresent(presentId);
    }


    @RequestMapping("present/list")
    public Page<MedalPresent> listPresent(@RequestParam(defaultValue = "0") Integer page,
                                    @RequestParam(defaultValue = "10") Integer size) {
        return medalService.listPresent(page, size);
    }


    @RequestMapping("present/detail")
    public MedalPresent presentDetail(@RequestParam("presentId") Integer presentId) {
        return medalService.presentDetail(presentId);
    }

    @RequestMapping("present/find")
    public List<MedalPresent> findPresent() {
        return medalService.listPresent();
    }


}
